package com.leenmvc.core.utils;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPatch;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

/**
 * @Author: JohnCoding
 * @Description:
 * @date: 2020/5/28 11:32
 */
public class HttpUtils {

    /**
     * patch方法
     *
     * @param url  url
     * @param body body
     * @return
     */
    public static String doPatch(String url, String body) {
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPatch httpPatch = new HttpPatch(url);
        httpPatch.setEntity(new StringEntity(body, "utf-8"));
        CloseableHttpResponse response =null;
        String resultString = null;
        try {
            response = client.execute(httpPatch);
            resultString = EntityUtils.toString(response.getEntity());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return resultString;
    }


}
